﻿#region 导入名称空间

using Autofac;
using Topshelf.HostConfigurators;

#endregion

namespace LightWork.Topshelf.Autofac
{
    public static class HostConfiguratorExtensions
    {
        #region Public Methods and Operators

        public static HostConfigurator UseAutofacContainer(this HostConfigurator configurator,
            ILifetimeScope lifetimeScope)
        {
            configurator.AddConfigurator(new AutofacHostBuilderConfigurator(lifetimeScope));
            return configurator;
        }

        public static HostConfigurator UseCustomerConfigure(this HostConfigurator configurator)
        {
            var container = AutofacHostBuilderConfigurator.LifetimeScope;
            if (container.IsRegistered<CustomerHostConfiguration>())
            {
                var customerConfigure = container.Resolve<CustomerHostConfiguration>();
                customerConfigure.Configure(ref configurator);
            }

            return configurator;
        }

        #endregion
    }
}